<?php

//计算工资
//author:化缘

header("Content-type: text/html; charset=utf-8");
require('../mysql.php');
require('json.php');



//定义是按照量算的价格


//获取上个月的工资   select sum(count) from computebysize where studentid='20141010001' and timebegin>'2014-11-01 00:00:00'
   //测试数据  学号   20141120021
function getallecome($classid){
	//计算上个月的时间范围
	$year=date("Y");
    $month=date("m");
   
    $worktimebeginer=$year."-".$month."-"."01"." 00:00:00";
    $worktimeend=$year."-".$month."-"."31"." 00:00:00";
    $stringsql="SELECT count,price,timebegin,timeend FROM computebysize WHERE studentid =  '{$classid}' AND timebegin >'{$worktimebeginer}' AND timebegin < '$worktimeend'";
    $result=mysql_query($stringsql);
    $sum=0;
    $worktime=0;
     $sumandworktime=array();
   	while ($row = mysql_fetch_assoc($result)) {
   	$sum+=$row['count']*$row['price'];
    $worktime+=($row['timeend']-$row['timebegin']);
    //echo $row['timebegin']."\n";
   // echo $row['timeend']."\n";
   }
   $sumandworktime=array('sumprice' =>$sum,'worktime'=>$worktime);
   return $sumandworktime;
 }

function getpersonalinfo($classid){
   $stringsql="SELECT college FROM allstudent WHERE studentid = '{$classid}' ";
    $result=mysql_query($stringsql);
     $info;
    while ($row = mysql_fetch_assoc($result)) {
      $info=$row['college'];
     
   }
  // print_r($info) ;
   
   $getmoney=getallecome($classid);
   $Wage=array('college'=>$info,'priceinfo'=>$getmoney,'month'=>date("m"));
   echo encode_json($Wage);
 
}


//测试用例
//getpersonalinfo("20141120021");
?>

